package com.bdqn.mapper;

import com.bdqn.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    /**
     * 登录
     * @param userName：用户名
     * @param userPwd：用户密码
     * @return 用户对象
     */
    @Select("SELECT * FROM sys_user WHERE user_name=#{uName} AND `password`=#{uPwd} and status=1")
    User selectUser(@Param("uName") String userName,@Param("uPwd") String userPwd);

    List<User> selectAll(String name);

    @Insert("INSERT INTO `sys_user` VALUES (NULL,#{deptName}, #{userName}, #{usertype}, #{sex}, #{age}, #{picture}, #{background}, #{phone}, #{email}, #{strong}, #{honor}, #{introduction}, #{userRank}, #{password}, #{lastLoginTime}, #{lastLoginIp}, #{status}, #{unionId}, #{openId}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{salt},#{schedulingFlag})")
    int add(User user);

    int addRoles(@Param("uid") Integer uid,@Param("rids")  List<Integer> rids);



    @Select("select * from sys_user where user_id=#{id}")
    User selectById(int uid);

    @Delete("delete from sys_role_user where user_id=#{uid}")
    void deleteRole(Integer uid);
    @Update("UPDATE sys_user SET dept_name = #{deptName},user_name = #{userName},user_type = #{userType},sex = #{sex},age = #{age},picture = #{picture},background = #{background},phone = #{phone},email = #{email},strong = #{strong},honor = #{honor},introduction = #{introduction},user_rank = #{userRank},password = #{password},last_login_time = #{lastLoginTime},last_login_ip = #{lastLoginIp},status = #{status},union_id = #{unionId},open_id = #{openId},create_time = #{createTime},update_time = #{updateTime},create_by = #{createBy},update_by = #{updateBy},salt = #{salt},scheduling_flag = #{schedulingFlag} WHERE user_id = #{userId}")
    int updateUser(User user);
    @Delete("DELETE FROM sys_user WHERE user_id=#{uid}")
    int deleteUser(@Param("uid") int uid);
    @Update("update sys_user set status=0 where user_id=#{id}")
    int modifyStateClose(@Param("id") int id);
    @Update("update sys_user set status=1 where user_id=#{id}")
    int modifyStateOpen(@Param("id") int id);
}
